class TransactionOperations:
    def __init__(self, db, card_id):
        self.db = db
        self.card_id = card_id

    def deposit(self, amount):
        # 存款操作（数据库触发器将自动记录）
        query = "UPDATE cardinfo SET balance = balance + %s WHERE cardID = %s"
        self.db.execute_query(query, (amount, self.card_id))
        print(f"存款{amount}元成功")

    def withdraw(self, amount):
        # 取款操作（数据库触发器将自动记录）
        query = "UPDATE cardinfo SET balance = balance - %s WHERE cardID = %s"
        self.db.execute_query(query, (amount, self.card_id))
        print(f"取款{amount}元成功")

    def transfer(self, target_card_id, amount):
        # 参数校验（6.20改）
        if len(target_card_id) != 16:
            return {"success": False, "message": "卡号必须为16位"}
        if amount <= 0:
            return {"success": False, "message": "转账金额必须大于0"}

        # 调用专用方法（绕开通用execute_procedure）
        return self.execute_transfer_procedure(
            self.card_id, target_card_id, amount
        )

